For cases where we want a variation of an object with some keys added
or changed, use native Object.create() to create a plain object that
inherits from the other object (without needing to loop and copy each
key/value separately).
This optimisation only works, of course, if the original object
by-reference does not change later.
Also remove hasOwn filter from sortQuery, because it must now consider
inherited keys as well. This filter was already obsolete given mw.loader
already has many unfiltered for-in loops in other places, and just in
general doesn't support environments that extend Object.prototype.
Change-Id: Ib405e32d4598dfb94629c2596ea0804d1c13e7c0
a = [];
for ( key in o ) {
a = [];
for ( key in o ) {
- if ( hasOwn.call( o, key ) ) {
- a.push( key );
- }
}
a.sort();
for ( key = 0; key < a.length; key++ ) {
}
a.sort();
for ( key = 0; key < a.length; key++ ) {
* @param {string} sourceLoadScript URL of load.php
*/
function doRequest( moduleMap, currReqBase, sourceLoadScript ) {
* @param {string} sourceLoadScript URL of load.php
*/
function doRequest( moduleMap, currReqBase, sourceLoadScript ) {
- var query = $.extend(
- { modules: buildModulesString( moduleMap ) },
- currReqBase
- );
+ // Optimisation: Inherit (Object.create), not copy ($.extend)
+ var query = Object.create( currReqBase );
+ query.modules = buildModulesString( moduleMap );
query = sortQuery( query );
addScript( sourceLoadScript + '?' + $.param( query ) );
}
query = sortQuery( query );
addScript( sourceLoadScript + '?' + $.param( query ) );
}
// modules for this group from this source.
modules = splits[ source ][ group ];
// modules for this group from this source.
modules = splits[ source ][ group ];
- currReqBase = $.extend( {
- version: getCombinedVersion( modules )
- }, reqBase );
+ // Optimisation: Inherit (Object.create), not copy ($.extend)
+ currReqBase = Object.create( reqBase );
+ currReqBase.version = getCombinedVersion( modules );
+
// For user modules append a user name to the query string.
if ( group === 'user' && mw.config.get( 'wgUserName' ) !== null ) {
currReqBase.user = mw.config.get( 'wgUserName' );
// For user modules append a user name to the query string.
if ( group === 'user' && mw.config.get( 'wgUserName' ) !== null ) {
currReqBase.user = mw.config.get( 'wgUserName' );